<%@ page import="com.touzi.constants.MobileCons" %>
<%@ page import="com.touzi.utils.MyHTTPUtils" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.touzi.constants.DbCons" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="com.touzi.beans.dbs.users.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.touzi.beans.dbs.dingdan.AUserDingd" %>
<%@ page import="com.touzi.beans.dbs.liushui.Liushui" %>
<%@ page import="com.touzi.beans.dbs.yongjin.Yongjin" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.touzi.mapper.*" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="com.touzi.proconfig.ProjectConfig" %>
<%@ page import="java.math.RoundingMode" %>
<%@ page import="com.touzi.beans.dbs.quanqiufenhong.QqfhJilu" %>
<%@ page import="com.touzi.beans.dbs.tongji.QqfhUser" %><%--
  Created by IntelliJ IDEA.
  User: w7851
  Date: 2018/5/16
  Time: 7:49
  全球分红页面
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
    Cookie usercookie = MyHTTPUtils.getCookieByName(request, MobileCons.COOKIE_USERNAME);
    if (usercookie == null) {
        response.sendRedirect("/mobile?method=exitlog");
        return;
    }

    String userphone = usercookie.getValue();
    SqlSession sqlSession = ((SqlSessionFactory) application.getAttribute(DbCons.DB_FACTORY)).openSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    TongjiMapper tongjiMapper = sqlSession.getMapper(TongjiMapper.class);
    QqfhMapper qqfhMapper = sqlSession.getMapper(QqfhMapper.class);

    User user = userMapper.findUserByDhmw(userphone).get(0);
    if (user == null) {
        response.sendRedirect("/mobile?method=exitlog");
        sqlSession.close();
        return;
    }

    int jryxzt = tongjiMapper.getTodayYXTJ(user.id);
    int dachengren = tongjiMapper.findQqfhCount();

    float jrys = 0.0f;  //今日营收
    try {
        jrys = Float.parseFloat(tongjiMapper.jinriYingshou());
    } catch (Exception e) {
        jrys = 0.0f;
    }
    String jiangjinchi = (new BigDecimal(jrys)).multiply(new BigDecimal(ProjectConfig.QQFH_PERCENT)).setScale(2, RoundingMode.DOWN).toString();
    List<QqfhJilu> userQqfh = qqfhMapper.getAUserQqfhJilu(user.id);
    request.setAttribute("userQqfh", userQqfh);

    sqlSession.close();
%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全球分红</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>

    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>

    <link rel="stylesheet" href="/css/ydui.css">
    <script src="/js/ydui.flexible.js"></script>
</head>
<body>
<div class="g-flexview">
    <header class="m-navbar  navbar-fixed">
        <a onclick="goback()" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">全球分红</span></div>
    </header>


    <div class="g-scrollview" style="margin-top: 1rem">

        <div class="m-celltitle">今日业绩</div>
        <ul class="m-grids-3">
            <li class="grids-item">
                <div class="grids-txt">今日直推:<%=jryxzt%>
                </div>
            </li>
            <li class="grids-item">
                <div class="grids-txt">达成人数:<%=dachengren%>
                </div>
            </li>
            <li class="grids-item">
                <div class="grids-txt">奖金池:<%=jiangjinchi%>
                </div>
            </li>
        </ul>

        <aside class="demo-tip" style="padding: 16px;color: #474544">
            <p>规则说明：</p>
            <p>系统将每日销售额的5%作为奖励，平均分给参与用户。每日有效直推5人即可参与。</p>
            <p style="margin-top: 6px">有效直推用户是指直接推荐并参与消费的用户！</p>
            <p>分红时间是第二天的凌晨30分。奖金池每10分钟更新。</p>
        </aside>
        <hr style="background:#d9d9d9;border:none;height: 1px;width: 100%">


        <div class="m-celltitle" style="margin-top: 16px">我的往期分红记录</div>
        <div class="m-cell">
            <c:forEach var="item" items="${userQqfh}">
                <a class="cell-item" href="javascript:;">
                    <div class="cell-left">${item.jiner}</div>
                    <div class="cell-right">${item.shijian}</div>
                </a>
            </c:forEach>
        </div>


    </div>
</div>
</body>
<script>
    function goback() {
        history.go(-1);
    }
</script>
</html>
